package com.jh.cloud.nativeApplication;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.FileInputStream;
import java.util.Properties;

@SpringBootApplication
@RestController
public class NativeApplication {
    public static void main(String[] args) throws Exception{

        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
        context.setId("我的天");
        // 将一个bean注册到 "我的天" 这个上下文的 beanFactory中，这个上下文又是启动的上下文的父级，所以子级也能使用这个bean
        context.registerBean("helloWorld", String.class, "Hello World");
        context.refresh();

        new SpringApplicationBuilder(NativeApplication.class)
                .parent(context) //显式指定父级
                .run(args);

        //SpringApplication.run(NativeApplication.class, args);
    }

    @Autowired
    @Qualifier("helloWorld")
    private String message;

    @RequestMapping("")
    public String findMessage() {
        return this.message;
    }
}
